package controller

import (
	"github.com/gin-gonic/gin"
	"kf/models/dao"
)

type AboutController struct {
	AboutDao *dao.AboutDao
}

func (aboutController *AboutController) GetAbout(c *gin.Context) {
	page := c.Query("page")
	if page == "" {
		page = "index"
	}
	about := aboutController.AboutDao.FindAboutByPage(page)
	c.JSON(200, gin.H{
		"code":   200,
		"msg":    "ok",
		"result": about,
	})
}
func (aboutController *AboutController) GetAbouts(c *gin.Context) {
	about := aboutController.AboutDao.FindAbouts()
	c.JSON(200, gin.H{
		"code":   200,
		"msg":    "ok",
		"result": about,
	})
}
func (aboutController *AboutController) PostAbout(c *gin.Context) {
	titleCn := c.PostForm("title_cn")
	titleEn := c.PostForm("title_en")
	keywordsCn := c.PostForm("keywords_cn")
	keywordsEn := c.PostForm("keywords_en")
	descCn := c.PostForm("desc_cn")
	descEn := c.PostForm("desc_en")
	cssJs := c.PostForm("css_js")
	htmlCn := c.PostForm("html_cn")
	htmlEn := c.PostForm("html_en")
	if titleCn == "" || titleEn == "" || htmlCn == "" || htmlEn == "" {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "error",
		})
		return
	}
	aboutController.AboutDao.UpdateAbout("index", titleCn, titleEn, keywordsCn, keywordsEn, descCn, descEn, cssJs, htmlCn, htmlEn)

	c.JSON(200, gin.H{
		"code":   200,
		"msg":    "ok",
		"result": "",
	})
}
